﻿using UnityEngine;
using System.Collections;

public class GameHallWindow : BaseWidget
{

    public UILabel SystemNews;
    public UILabel OnLineNumber;
    public UILabel PlayerName;

    public GameObject MatchGameBtn; 
    public GameObject CurMatchInfo;
    public UILabel CurMatchTimeLabel;

    GameHallModel gameHallModel;
    int MachWaitTime;  //匹配排队等待时间.
    float matchAddTime; 
    public override void OnLoad()
    {
       PlayerModel playerModel = Game.Model.NewGet<PlayerModel>();
       PlayerName.text = playerModel.UserName;
       gameHallModel = Game.Model.NewGet<GameHallModel>();
       SystemNews.text = gameHallModel.SystemNews;
       OnLineNumber.text = gameHallModel.OnLineNumber.ToString();
    }

  

    //点击快速匹配
    public void OnClick_MatchGame() 
    {
        Game.Packet.SendMatchGame();
    }
    //快速匹配成功.
    public void RetMatchGameOK()
    {
        MatchGameBtn.SetActive(false);
        CurMatchInfo.SetActive(true);
        MachWaitTime = 0;
        matchAddTime = 0;
        CurMatchTimeLabel.text = "0秒";
    }
    //取消匹配
    public void OnClick_CancelMatch() 
    {
        Game.Packet.SendCancelMatch();
    }
    //取消匹配成功.
    public void RetCancelMatchOK()
    {
        MatchGameBtn.SetActive(true);
        CurMatchInfo.SetActive(false);
    }

    public void Update()
    {

        if (CurMatchInfo.activeSelf)
        {
            matchAddTime += Time.deltaTime;
            if (matchAddTime >= 1) 
            {
                MachWaitTime++;
                CurMatchTimeLabel.text = MachWaitTime.ToString() + "秒";
                matchAddTime = 0;
            }
        }
        OnLineNumber.text = gameHallModel.OnLineNumber.ToString();
    }
}
